#include"CompBioTools.hh"

#ifndef _CROSSMATCH
#define _CROSSMATCH

class CrossmatchResult{
public:
  int   mScore;
  float mSubstitutions;
  float mDeletions;
  float mInsertions;
  string mQueryName;
  long mQueryStart;
  long mQueryEnd;
  bool mbIsReverse;
  string mSourceName;
  long mSourceStart;
  long mSourceEnd;
  bool mbIsContained; 

  void PrintSingleSource(ostream &fout){

	 //fout.width(20);
	 //fout<<C.mName;
	 PrintSpacePaddedString(fout,16,mQueryName);
	 fout<<"\t"<<mSourceStart<<"\t"<<mSourceEnd<<endl;
  }


  void Print(ostream &fout){
	 fout<<mScore<<"\t"<<mSourceName<<"\t"<<mQueryName<<endl;
  }

  void PrintVerbose(ostream &fout){
	 fout<<"mScore="<<mScore<<endl;
	 fout<<"mSubstitutions="<<mSubstitutions<<"  ";
	 fout<<"mDeletions="<<mDeletions<<"  ";
	 fout<<"mInsertions="<<mInsertions<<endl;
	 fout<<"VName="<<mQueryName<<endl;
	 fout<<"QueryStart="<<mQueryStart<<" QueryEnd="<<mQueryEnd<<endl;
	 fout<<"IsReverse="<<mbIsReverse<<endl;
	 fout<<"SourceName = "<<mSourceName<<endl;
	 fout<<"SourceStart="<<mSourceStart<<endl;
	 fout<<"SourceEnd="<<mSourceEnd<<endl;
  }
};


class Crossmatch : public vector<CrossmatchResult>{
public:

  void Read(string FileName);

  int TotalSize(){
	 int totalSize = 0;
	 for(int i = 0;i< size();i++){
		int cSize = (*this)[i].mSourceEnd - (*this)[i].mSourceStart +1;
		totalSize+=abs(cSize);
	 }
	 return(totalSize);
  }


  void GetSinks(string &SourceName,vector<string> &Sinks,int minScore);
  void DFSSink(string &SourceName,StringSet &SomeComponent,
					StringSet &ThisComponent, int minScore);

  void AddInverseEdges();
  void FindConnectedComponents(vector<StringSet> &Components,int minScore);

};

#endif 


/*

Standard output

  The standard output lists matches between any sequence in the first
input file (the "query" sequences) and a sequence in the second (or
later) input file (the "subject" sequences); or, if a single input
file is provided, the matches between any two sequences in this file.
The matches that are reported are controlled by the command line
options -minscore and -masklevel, as well as by the options that
control scoring of the alignments and the band search (see section IV
above).  The reported matches are ordered by query, and for each query
by the position of the start of the alignment within the query.
  For each reported match, an initial output line gives summary
information:

 Example: 

440  2.38 1.39 0.79  hh44a1.s1       33   536 (    0)  C 00311     ( 3084)  8277   7771  * 

Interpretation:
  440 = smith-waterman score of the match (complexity-adjusted, by default).
  2.38 = %substitutions in matching region
  1.39 = %deletions (in 1st seq rel to 2d) in matching region
  0.79 = %insertions (in 1st seq rel to 2d) in matching region 
  hh44a1.s1 = id of 1st sequence
  33 = starting position of match in 1st sequence
  536 = ending position of match in 1st sequence
  (0) = no. of bases in 1st sequence past the ending position of match
         (so 0 means that the match extended all the way to the end of 
          the 1st sequence)
  C 00311 : match is with the Complement of sequence 00311
  ( 3084) : there are 3084 bases in (complement of) 2d sequence prior to 
        beginning of the match
  8277 = starting position of match in 2d sequence (using top-strand 
         numbering)
  7771 =  ending position of match in 2d sequence
  * indicates that there is a higher-scoring match whose domain partly
includes the domain of this match.

*/
